<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Python3.0学习Python基础篇概念 python 是一种解释性、面向对象、动态数据类型的高级程序设计语言  1989年底发明，Gudio van Rossum ，第一个公开发行版本1991年  2020.1.1，停止python2 的更新，python2.7被确定为最后一个python2.x版本   CMD命令 python -v python 编译 python 文件名.py 输出">
<meta property="og:type" content="article">
<meta property="og:title" content="Python学习">
<meta property="og:url" content="http://yoursite.com/2020/02/22/%E5%90%8E%E7%AB%AF/python/Python%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="heweiliang blog">
<meta property="og:description" content="Python3.0学习Python基础篇概念 python 是一种解释性、面向对象、动态数据类型的高级程序设计语言  1989年底发明，Gudio van Rossum ，第一个公开发行版本1991年  2020.1.1，停止python2 的更新，python2.7被确定为最后一个python2.x版本   CMD命令 python -v python 编译 python 文件名.py 输出">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-02-22T11:23:07.564Z">
<meta property="article:modified_time" content="2020-06-26T08:18:17.127Z">
<meta property="article:author" content="heweiliang">
<meta property="article:tag" content="Python">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/02/22/%E5%90%8E%E7%AB%AF/python/Python%E5%AD%A6%E4%B9%A0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Python学习 | heweiliang blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="heweiliang blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">heweiliang blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/yourname" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/02/22/%E5%90%8E%E7%AB%AF/python/Python%E5%AD%A6%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="heweiliang">
      <meta itemprop="description" content="heweiliang blog">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="heweiliang blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Python学习<a href="https://github.com/user-name/repo-name/tree/branch-name/subdirectory-name_posts/%E5%90%8E%E7%AB%AF/python/Python%E5%AD%A6%E4%B9%A0.md" class="post-edit-link" title="编辑" rel="noopener" target="_blank"><i class="fa fa-pencil"></i></a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-02-22 19:23:07" itemprop="dateCreated datePublished" datetime="2020-02-22T19:23:07+08:00">2020-02-22</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-06-26 16:18:17" itemprop="dateModified" datetime="2020-06-26T16:18:17+08:00">2020-06-26</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index"><span itemprop="name">Python</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="Python3-0学习"><a href="#Python3-0学习" class="headerlink" title="Python3.0学习"></a>Python3.0学习</h1><h2 id="Python基础篇"><a href="#Python基础篇" class="headerlink" title="Python基础篇"></a>Python基础篇</h2><h4 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h4><ul>
<li><p>python 是一种解释性、面向对象、动态数据类型的高级程序设计语言</p>
</li>
<li><p>1989年底发明，Gudio van Rossum ，第一个公开发行版本1991年</p>
</li>
<li><p>2020.1.1，停止python2 的更新，python2.7被确定为最后一个python2.x版本</p>
</li>
</ul>
<p>CMD命令</p>
<p>python -v</p>
<p>python</p>
<p>编译 python 文件名.py</p>
<p>输出</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(<span class="string">"Hello Python!!!"</span>);</span><br></pre></td></tr></table></figure>

<h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><p>Windows环境变量</p>
<p>cmd检查</p>
<p>python -v</p>
<p>环境搭建</p>
<p>两种方式</p>
<p>方法一</p>
<p>path=%path%;目录</p>
<p>方法二</p>
<h4 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h4><h5 id="基本语法"><a href="#基本语法" class="headerlink" title="基本语法"></a>基本语法</h5><h6 id="编程类型"><a href="#编程类型" class="headerlink" title="编程类型"></a>编程类型</h6><ul>
<li><p>交互式编程</p>
<p>交互式编程不需要创建脚本文件，是通过Python解析器的交互模式进来编写代码。</p>
</li>
<li><p>脚本式编程</p>
<p>通过脚本参数调用解析器开始执行脚本，直到脚本执行完毕。当脚本执行完成后，解析器不再有效</p>
</li>
</ul>
<h6 id="行与缩进"><a href="#行与缩进" class="headerlink" title="行与缩进"></a>行与缩进</h6><p>python最具特色的就是使用缩进来表示代码块，不需要使用大括号 <strong>{}</strong> 。</p>
<p>缩进的空格数是可变的，但是同一个代码块的语句必须包含相同的缩进空格数。</p>
<h5 id="多行语句"><a href="#多行语句" class="headerlink" title="多行语句"></a>多行语句</h5><p>Python 通常是一行写完一条语句，但如果语句很长，我们可以使用反斜杠(\ )来实现多行语句</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">total = item_one + \</span><br><span class="line">        item_two + \</span><br><span class="line">        item_three</span><br></pre></td></tr></table></figure>

<p>在 [], {}, 或 () 中的多行语句，不需要使用反斜杠()，例如：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">total = [<span class="string">'item_one'</span>, <span class="string">'item_two'</span>, <span class="string">'item_three'</span>,</span><br><span class="line">        <span class="string">'item_four'</span>, <span class="string">'item_five'</span>]</span><br></pre></td></tr></table></figure>

<h6 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h6><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 单行注释</span></span><br><span class="line"></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">多行注释</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="string">多行注释</span></span><br><span class="line"><span class="string">"""</span></span><br></pre></td></tr></table></figure>

<h6 id="中文编码"><a href="#中文编码" class="headerlink" title="中文编码"></a>中文编码</h6><p>Python中默认的编码格式是 ASCII 格式，在没修改编码格式时无法正确打印汉字，所以在读取中文时会报错。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SyntaxError: Non-ASCII character <span class="string">'\xe4'</span> <span class="keyword">in</span> file test.py on line <span class="number">2</span>, but no encoding declared; see http://www.python.org/peps/pep<span class="number">-0263.</span>html <span class="keyword">for</span> details</span><br></pre></td></tr></table></figure>

<p>解决方法为只要在文件开头加入 <strong># -*- coding: UTF-8 -*-</strong> 或者 <strong># coding=utf-8</strong> 就行了</p>
<p><strong>注意：</strong> <strong># coding=utf-8</strong> <em>的</em> <strong>=</strong> <em>号两边不要空格。</em></p>
<p><strong>注意：*</strong>Python3.X 源码文件默认使用utf-8编码，所以可以正常解析中文，无需指定 UTF-8 编码。*</p>
<p>Pycharm 设置步骤：</p>
<ul>
<li>进入 <strong>file &gt; Settings</strong>，在输入框搜索 <strong>encoding</strong>。</li>
<li>找到 <strong>Editor &gt; File encodings</strong>，将 <strong>IDE Encoding</strong> 和 <strong>Project Encoding</strong> 设置为utf-8。</li>
</ul>
<p>所有字符串都是unicode字符串</p>
<p>标识符和保留字</p>
<p>标识符</p>
<p>第一个字符必须是字母表中或下划线 _</p>
<p>大小写敏感</p>
<p>标识符地其他的部分由字母、数字和下划线组成。 </p>
<p>保留字</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">import keyword</span><br><span class="line">print(keyword.kwlist)</span><br></pre></td></tr></table></figure>





<h6 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h6><h5 id="语句"><a href="#语句" class="headerlink" title="语句"></a>语句</h5><p>循环语句</p>
<p>for()</p>
<p>while()</p>
<p>do() while{</p>
<p>}</p>
<p>条件语句</p>
<p>if()</p>
<p>if(){}else{}</p>
<p>if(){}else if(){}else if{} else{}</p>
<h5 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h5><p>Python 中的变量不需要声明。每个变量在使用前都必须赋值，变量赋值以后该变量才会被创建。</p>
<p>在 Python 中，变量就是变量，它没有类型，我们所说的”类型”是变量所指的内存中对象的类型。</p>
<p>等号（=）用来给变量赋值。</p>
<p>等号（=）运算符左边是一个变量名,等号（=）运算符右边是存储在变量中的值。例如：</p>
<h5 id="多个变量赋值"><a href="#多个变量赋值" class="headerlink" title="多个变量赋值"></a>多个变量赋值</h5><p>Python允许你同时为多个变量赋值。例如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a &#x3D; b &#x3D; c &#x3D; 1</span><br></pre></td></tr></table></figure>

<p>以上实例，创建一个整型对象，值为 1，从后向前赋值，三个变量被赋予相同的数值。</p>
<p>您也可以为多个对象指定多个变量。例如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a, b, c &#x3D; 1, 2, &quot;runoob&quot;</span><br></pre></td></tr></table></figure>



<p>Python3 的六个标准数据类型中：</p>
<ul>
<li><strong>不可变数据（3 个）：</strong>Number（数字）、String（字符串）、Tuple（元组）；</li>
<li><strong>可变数据（3 个）：</strong>List（列表）、Dictionary（字典）、Set（集合）。</li>
</ul>
<ol>
<li><p>Number 数字</p>
<p>内置的type()函数可以查询变量所指的对象类型</p>
<p>print（type(a)）</p>
<p>isinstance(a,int) 判断与后面的类型是不是相同</p>
<ul>
<li>type()不会认为子类是一种父类类型。</li>
<li>isinstance()会认为子类是一种父类类型。</li>
</ul>
</li>
</ol>
<ul>
<li><p>int(整数)</p>
</li>
<li><p>只有一种整数类型int,表示为长整型i，没有python2中的Long</p>
</li>
<li><p>bool(布尔)</p>
</li>
<li><p>True或False</p>
</li>
<li><p>float(浮点数)</p>
</li>
<li><p>complex(复数)</p>
</li>
<li><p>Python还支持复数，复数由实数部分和虚数部分构成，可以用a + bj,或者complex(a,b)表示， 复数的实部a和虚部b都是浮点型</p>
</li>
<li><p>1+2j、1.1+2.2j</p>
</li>
<li><p>1、Python可以同时为多个变量赋值，如a, b = 1, 2。</p>
</li>
<li><p>2、一个变量可以通过赋值指向不同类型的对象。</p>
</li>
<li><p>3、数值的除法包含两个运算符：<strong>/</strong> 返回一个浮点数，<strong>//</strong> 返回一个整数。</p>
</li>
<li><p>4、在混合计算时，Python会把整型转换成为浮点数。</p>
<p>当你指定一个值时，Number 对象就会被创建：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var1 &#x3D; 1</span><br><span class="line">var2 &#x3D; 10</span><br></pre></td></tr></table></figure>

<p>您也可以使用del语句删除一些对象引用。</p>
<p>del语句的语法是：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">del var1[,var2[,var3[....,varN]]]</span><br></pre></td></tr></table></figure>

<p>您可以通过使用del语句删除单个或多个对象。例如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">del var</span><br><span class="line">del var_a, var_b</span><br></pre></td></tr></table></figure>

<p>&gt;&gt;&gt; 2 / 4  # 除法，得到一个浮点数 0.5 &gt;&gt;&gt; 2 // 4 # 除法，得到一个整数 0 &gt;&gt;&gt; 17 % 3 # 取余  2 &gt;&gt;&gt; 2 ** 5 # 乘方 32</p>
</li>
</ul>
<ol start="2">
<li>字符串String(不能被改变)</li>
</ol>
<ul>
<li><p>python中单引号和双引号使用完全相同。</p>
</li>
<li><p>加号 <strong>+</strong> 是字符串的连接符， 星号 ***** 表示复制当前字符串，与之结合的数字为复制的次数。实例如下：</p>
</li>
<li><p>使用三引号(‘’’或”””)可以指定一个多行字符串。</p>
</li>
<li><p>转义符 ‘ \ ‘</p>
</li>
<li><p>反斜杠可以用来转义，使用r可以让反斜杠不发生转义。。 如 r”this is a line with \n” 则\n会显示，并不是换行。</p>
</li>
<li><p>按字面意义级联字符串，如”this “ “is “ “string”会被自动转换为this is string。</p>
</li>
<li><p>字符串可以用 + 运算符连接在一起，用 * 运算符重复。</p>
</li>
<li><p>Python 中的字符串有两种索引方式，从左往右以 0 开始，从右往左以 -1 开始。</p>
</li>
<li><p>索引值以 0 为开始值，-1 为从末尾的开始位置。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(str[0:-2])  # 输出第一个到倒数第二个的所有字符</span><br></pre></td></tr></table></figure>
</li>
<li><p>Python中的字符串不能改变。</p>
</li>
<li><p>Python 没有单独的字符类型，一个字符就是长度为 1 的字符串。</p>
</li>
<li><p>字符串的截取的语法格式如下：<strong>变量[头下标:尾下标:步长]</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(str[2:])  # 输出从第三个开始后的所有字符</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(str[2:5])  # 输出从第三个开始到第五个的字符</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#可以将字符串输出任意次数</span><br><span class="line">print(str * 2)  # 输出字符串两次列表</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ol start="3">
<li><p>字典(Dictionary) {}</p>
<p>字典（dictionary）是python中另一个非常有用的内置数据类型</p>
<p>列表是有序的对象集合，字典是无序的对象集合。两者之间的区别在于：字典当中的元素是通过键来存取的，而不是通过偏移存取。</p>
<p>字典是一种映射类型，字典用 <strong>{ }</strong> 标识，它是一个无序的 <strong>键(key) : 值(value)</strong> 的集合。</p>
<p>键(key)必须使用不可变类型。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tinydict &#x3D; &#123;&#39;name&#39;: &#39;runoob&#39;,&#39;code&#39;:1, &#39;site&#39;: &#39;www.runoob.com&#39;&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>1、字典是一种映射类型，它的元素是键值对。</p>
</li>
<li><p>2、字典的关键字必须为不可变类型，且不能重复。</p>
</li>
<li><p>3、创建空字典使用 <strong>{ }</strong>。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">dict &#x3D; &#123;&#125;</span><br><span class="line">dict[&#39;one&#39;] &#x3D; &quot;1 - 菜鸟教程&quot;</span><br><span class="line">dict[2]     &#x3D; &quot;2 - 菜鸟工具&quot;</span><br><span class="line"> </span><br><span class="line">tinydict &#x3D; &#123;&#39;name&#39;: &#39;runoob&#39;,&#39;code&#39;:1, &#39;site&#39;: &#39;www.runoob.com&#39;&#125;</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">print (dict[&#39;one&#39;])       # 输出键为 &#39;one&#39; 的值</span><br><span class="line">print (dict[2])           # 输出键为 2 的值</span><br><span class="line">print (tinydict)          # 输出完整的字典</span><br><span class="line">print (tinydict.keys())   # 输出所有键</span><br><span class="line">print (tinydict.values()) # 输出所有值</span><br></pre></td></tr></table></figure>

<p>构造函数 dict() 可以直接从键值对序列中构建字典如下：</p>
<h2 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&gt;&gt;&gt;dict([(&#39;Runoob&#39;, 1), (&#39;Google&#39;, 2), (&#39;Taobao&#39;, 3)])</span><br><span class="line">&#123;&#39;Taobao&#39;: 3, &#39;Runoob&#39;: 1, &#39;Google&#39;: 2&#125;</span><br><span class="line"> </span><br><span class="line">&gt;&gt;&gt; &#123;x: x**2 for x in (2, 4, 6)&#125;</span><br><span class="line">&#123;2: 4, 4: 16, 6: 36&#125;</span><br><span class="line"> </span><br><span class="line">&gt;&gt;&gt; dict(Runoob&#x3D;1, Google&#x3D;2, Taobao&#x3D;3)</span><br><span class="line">&#123;&#39;Runoob&#39;: 1, &#39;Google&#39;: 2, &#39;Taobao&#39;: 3&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
</li>
</ol>
<ol start="4">
<li><p>集合（Set） { } set()函数创建</p>
<p>集合（Set）是由一个或者数个形态各异的大小整体形成的，构成集合的事物或对象称作元素或是成员。</p>
<p>空集合必须用set(),而不是{ }，因为{ } 是用来创建一个空字典</p>
<p>创建格式</p>
<p>parme = { value01,value02,…..}</p>
<p>或者</p>
<p>set(value)</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># set可以进行集合运算</span></span><br><span class="line">a = set(<span class="string">'abracadabra'</span>)</span><br><span class="line">b = set(<span class="string">'alacazam'</span>)</span><br><span class="line"> </span><br><span class="line">print(a)</span><br><span class="line"> </span><br><span class="line">print(a - b)     <span class="comment"># a 和 b 的差集</span></span><br><span class="line"> </span><br><span class="line">print(a | b)     <span class="comment"># a 和 b 的并集</span></span><br><span class="line"> </span><br><span class="line">print(a &amp; b)     <span class="comment"># a 和 b 的交集</span></span><br><span class="line"> </span><br><span class="line">print(a ^ b)     <span class="comment"># a 和 b 中不同时存在的元素</span></span><br></pre></td></tr></table></figure>









</li>
</ol>
<ol start="5">
<li><p>列表(List) 用[] 号</p>
<p>List（列表） 是 Python 中使用最频繁的数据类型。</p>
<p>列表可以完成大多数集合类的数据结构实现。列表中元素的类型可以不相同，它支持数字，字符串甚至可以包含列表（所谓嵌套）。</p>
<p>列表是写在方括号 <strong>[]</strong> 之间、用逗号分隔开的元素列表。</p>
<p>和字符串一样，列表同样可以被索引和截取，列表被截取后返回一个包含所需元素的新列表。</p>
<p>列表截取的语法格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">变量[头下标:尾下标] #尾标没有取到</span><br></pre></td></tr></table></figure>

<p>索引值以 0 为开始值，-1 为从末尾的开始位置。</p>
<p>加号 <strong>+</strong> 是列表连接运算符，星号 ***** 是重复操作。如下实例：</p>
<p>与Python字符串不一样的是，列表中的元素是可以改变的：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">a[2:5] &#x3D; [13,14,15]</span><br><span class="line">a[2:5] &#x3D; []</span><br></pre></td></tr></table></figure>

<p><strong>注意：</strong></p>
<ul>
<li><p>1、List写在方括号之间，元素用逗号隔开。</p>
</li>
<li><p>2、和字符串一样，list可以被索引和切片。</p>
</li>
<li><p>3、List可以使用+操作符进行拼接。</p>
</li>
<li><p>4、List中的元素是可以改变的。</p>
</li>
<li><p>Python 列表截取可以接收第三个参数，参数作用是截取的步长，以下实例在索引 1 到索引 4 的位置并设置为步长为 2（间隔一个位置）来截取字符串：</p>
</li>
<li><p>如果第三个参数为负数表示逆向读取，</p>
</li>
<li><p>如果第三个参数为负数表示逆向读取，以下实例用于翻转字符串：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">实例</span><br><span class="line"></span><br><span class="line">**def** reverseWords(input):</span><br><span class="line"></span><br><span class="line">  \# 通过空格将字符串分隔符，把各个单词分隔为列表</span><br><span class="line">  inputWords &#x3D; input.split(&quot; &quot;)</span><br><span class="line"></span><br><span class="line">  \# 翻转字符串</span><br><span class="line">  \# 假设列表 list &#x3D; [1,2,3,4],  </span><br><span class="line">  \# list[0]&#x3D;1, list[1]&#x3D;2 ，而 -1 表示最后一个元素 list[-1]&#x3D;4 ( 与 list[3]&#x3D;4 一样)</span><br><span class="line">  \# inputWords[-1::-1] 有三个参数</span><br><span class="line">  \# 第一个参数 -1 表示最后一个元素</span><br><span class="line">  \# 第二个参数为空，表示移动到列表末尾</span><br><span class="line">  \# 第三个参数为步长，-1 表示逆向</span><br><span class="line">  inputWords&#x3D;inputWords[-1::-1]</span><br><span class="line"></span><br><span class="line">  \# 重新组合字符串</span><br><span class="line">  output &#x3D; &#39; &#39;.join(inputWords)</span><br><span class="line"></span><br><span class="line">  **return** output</span><br><span class="line"></span><br><span class="line">**if** __name__ &#x3D;&#x3D; &quot;__main__&quot;:</span><br><span class="line">  input &#x3D; &#39;I like runoob&#39;</span><br><span class="line">  rw &#x3D; reverseWords(input)</span><br><span class="line">  **print**(rw)</span><br></pre></td></tr></table></figure>



</li>
</ul>
</li>
</ol>
<ol start="6">
<li><p>元组(Tuple) 用（）号</p>
<p>元组（tuple）与列表类似，不同之处在于元组的元素不能修改。元组写在小括号 <strong>()</strong> 里，元素之间用逗号隔开。</p>
<p>元组中的元素类型也可以不相同：</p>
<p>元组与字符串类似，可以被索引且下标索引从0开始，-1 为从末尾开始的位置。也可以进行截取（看上面，这里不再赘述）。</p>
<p>其实，可以把字符串看作一种特殊的元组。</p>
<p>tup[0] = 11  # 修改元组元素的操作是非法的</p>
<p>虽然tuple的元素不可改变，但它可以包含可变的对象，比如list列表。</p>
<p>构造包含 0 个或 1 个元素的元组比较特殊，所以有一些额外的语法规则：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tup2 &#x3D; (20,) # 一个元素，需要在元素后添加逗号</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">tup1 &#x3D; ()    # 空元组</span><br><span class="line">tup2 &#x3D; (20,) # 一个元素，需要在元素后添加逗号</span><br></pre></td></tr></table></figure>

<p>string、list 和 tuple 都属于 sequence（序列）。</p>
<p><strong>注意：</strong></p>
<ul>
<li>1、与字符串一样，元组的元素不能修改。</li>
<li>2、元组也可以被索引和切片，方法一样。</li>
<li>3、注意构造包含 0 或 1 个元素的元组的特殊语法规则。</li>
<li>4、元组也可以使用+操作符进行拼接。</li>
</ul>
</li>
</ol>
<p>python结束不用分号</p>
<p>数据类型转换</p>
<h2 id="Python数据类型转换"><a href="#Python数据类型转换" class="headerlink" title="Python数据类型转换"></a>Python数据类型转换</h2><p>有时候，我们需要对数据内置的类型进行转换，数据类型的转换，你只需要将数据类型作为函数名即可。</p>
<p>以下几个内置的函数可以执行数据类型之间的转换。这些函数返回一个新的对象，表示转换的值。</p>
<table>
<thead>
<tr>
<th align="left">函数</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-int.html" target="_blank" rel="noopener">int(x [,base])</a></td>
<td align="left">将x转换为一个整数</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-float.html" target="_blank" rel="noopener">float(x)</a></td>
<td align="left">将x转换到一个浮点数</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-complex.html" target="_blank" rel="noopener">complex(real [,imag])</a></td>
<td align="left">创建一个复数</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-str.html" target="_blank" rel="noopener">str(x)</a></td>
<td align="left">将对象 x 转换为字符串</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-repr.html" target="_blank" rel="noopener">repr(x)</a></td>
<td align="left">将对象 x 转换为表达式字符串</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-eval.html" target="_blank" rel="noopener">eval(str)</a></td>
<td align="left">用来计算在字符串中的有效Python表达式,并返回一个对象</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python3-func-tuple.html" target="_blank" rel="noopener">tuple(s)</a></td>
<td align="left">将序列 s 转换为一个元组</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python3-att-list-list.html" target="_blank" rel="noopener">list(s)</a></td>
<td align="left">将序列 s 转换为一个列表</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-set.html" target="_blank" rel="noopener">set(s)</a></td>
<td align="left">转换为可变集合</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-dict.html" target="_blank" rel="noopener">dict(d)</a></td>
<td align="left">创建一个字典。d 必须是一个 (key, value)元组序列。</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-frozenset.html" target="_blank" rel="noopener">frozenset(s)</a></td>
<td align="left">转换为不可变集合</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-chr.html" target="_blank" rel="noopener">chr(x)</a></td>
<td align="left">将一个整数转换为一个字符</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-ord.html" target="_blank" rel="noopener">ord(x)</a></td>
<td align="left">将一个字符转换为它的整数值</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-hex.html" target="_blank" rel="noopener">hex(x)</a></td>
<td align="left">将一个整数转换为一个十六进制字符串</td>
</tr>
<tr>
<td align="left"><a href="https://www.runoob.com/python3/python-func-oct.html" target="_blank" rel="noopener">oct(x)</a></td>
<td align="left">将一个整数转换为一个八进制字符串</td>
</tr>
</tbody></table>
<h5 id="空行"><a href="#空行" class="headerlink" title="空行"></a>空行</h5><p>函数之间或类的方法之间用空行分隔，表示一段新的代码的开始。类和函数入口之间也用一行空行分隔，以突出函数入口的开始。</p>
<p>空行与代码缩进不同，空行并不是Python语法的一部分。书写时不插入空行，Python解释器运行也不会出错。但是空行的作用在于分隔两段不同功能或含义的代码，便于日后代码的维护或重构。</p>
<p><strong>记住：</strong>空行也是程序代码的一部分。</p>
<h5 id="同一行显示多条语句"><a href="#同一行显示多条语句" class="headerlink" title="同一行显示多条语句"></a>同一行显示多条语句</h5><p>python可以在同一行中使用多条语句，语句之间使用分号; 分割</p>
<p>import sys; x = “runoob”; sys.stdout.write(x+”\n”)</p>
<h5 id="多个语句构成代码组"><a href="#多个语句构成代码组" class="headerlink" title="多个语句构成代码组"></a>多个语句构成代码组</h5><p>缩进相同的一组语句构成一个代码块，就是代码组</p>
<h5 id="命令行参数"><a href="#命令行参数" class="headerlink" title="命令行参数"></a>命令行参数</h5><p>很多程序可以执行一些操作来查看一些基本信息</p>
<p>python -h 可以使用来查看各参数帮助信息</p>
<h5 id="import与from…import"><a href="#import与from…import" class="headerlink" title="import与from…import"></a>import与from…import</h5><p>在python中用import或者from…import来导入相应的模块 函数</p>
<p>将整个模块(somemodule)导入，格式为： <strong>import somemodule</strong></p>
<p>从某个模块中导入某个函数,格式为： <strong>from somemodule import somefunction</strong></p>
<p>从某个模块中导入多个函数,格式为： <strong>from somemodule import firstfunc, secondfunc, thirdfunc</strong></p>
<p>将某个模块中的全部函数导入，格式为： <strong>from somemodule import  *</strong></p>
<p>路径</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="comment"># 路径</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> sys.argv:</span><br><span class="line">	print(i)</span><br><span class="line"><span class="comment">#</span></span><br><span class="line">print(sys.path)</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">## 导入 sys 模块</span><br><span class="line">print (&#39;命令行参数为:&#39;)</span><br><span class="line">for i in sys.argv:    </span><br><span class="line">print (i) print (&#39;\n python 路径为&#39;,sys.path)</span><br></pre></td></tr></table></figure>



<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">## 导入 sys 模块的 argv,path 成员</span><br><span class="line"></span><br><span class="line">from sys import argv,path  #  导入特定的成员  </span><br><span class="line">print(&#39;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;python from import&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#39;) </span><br><span class="line">print(&#39;path:&#39;,path) # 因为已经导入path成员，所以此处引用时不需要加sys.path</span><br></pre></td></tr></table></figure>



<h5 id="解释器"><a href="#解释器" class="headerlink" title="解释器"></a>解释器</h5><h5 id="日期和时间"><a href="#日期和时间" class="headerlink" title="日期和时间"></a>日期和时间</h5><h5 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h5><h5 id="模块"><a href="#模块" class="headerlink" title="模块"></a>模块</h5><h5 id="文件I-O"><a href="#文件I-O" class="headerlink" title="文件I/O"></a>文件I/O</h5><h2 id="Python高级篇"><a href="#Python高级篇" class="headerlink" title="Python高级篇"></a>Python高级篇</h2><p>面向对象</p>
<p>正则表达式</p>
<p>CGI</p>
<p>MySQL</p>
<p>网络编程</p>
<p>SMATP</p>
<p>多线程</p>
<p>XML解析</p>
<p>GUI编程</p>
<p>IDE</p>
<p>JSON</p>

    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.jpg" alt="heweiliang 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="heweiliang 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Python/" rel="tag"># Python</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/02/19/%E8%BD%AF%E4%BB%B6/win10%E7%94%B5%E8%84%91%E6%8A%80%E5%B7%A7/" rel="prev" title="软件/win10电脑技巧">
      <i class="fa fa-chevron-left"></i> 软件/win10电脑技巧
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/02/23/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E8%A3%85%E4%B8%8E%E7%BB%B4%E6%8A%A4/" rel="next" title="计算机基础/计算机组装与维护">
      计算机基础/计算机组装与维护 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    
  <div class="comments">
    <div id="lv-container" data-id="city" data-uid="MTAyMC81MDY1MC8yNzEzMw=="></div>
  </div>
  

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Python3-0学习"><span class="nav-number">1.</span> <span class="nav-text">Python3.0学习</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Python基础篇"><span class="nav-number">1.1.</span> <span class="nav-text">Python基础篇</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#概念"><span class="nav-number">1.1.0.1.</span> <span class="nav-text">概念</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装"><span class="nav-number">1.1.0.2.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#语法"><span class="nav-number">1.1.0.3.</span> <span class="nav-text">语法</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#基本语法"><span class="nav-number">1.1.0.3.1.</span> <span class="nav-text">基本语法</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#编程类型"><span class="nav-number">1.1.0.3.1.1.</span> <span class="nav-text">编程类型</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#行与缩进"><span class="nav-number">1.1.0.3.1.2.</span> <span class="nav-text">行与缩进</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#多行语句"><span class="nav-number">1.1.0.3.2.</span> <span class="nav-text">多行语句</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#注释"><span class="nav-number">1.1.0.3.2.1.</span> <span class="nav-text">注释</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#中文编码"><span class="nav-number">1.1.0.3.2.2.</span> <span class="nav-text">中文编码</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#运算符"><span class="nav-number">1.1.0.3.2.3.</span> <span class="nav-text">运算符</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#语句"><span class="nav-number">1.1.0.3.3.</span> <span class="nav-text">语句</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#基本数据类型"><span class="nav-number">1.1.0.3.4.</span> <span class="nav-text">基本数据类型</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#多个变量赋值"><span class="nav-number">1.1.0.3.5.</span> <span class="nav-text">多个变量赋值</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例"><span class="nav-number">1.2.</span> <span class="nav-text">实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python数据类型转换"><span class="nav-number">1.3.</span> <span class="nav-text">Python数据类型转换</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#空行"><span class="nav-number">1.3.0.0.1.</span> <span class="nav-text">空行</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#同一行显示多条语句"><span class="nav-number">1.3.0.0.2.</span> <span class="nav-text">同一行显示多条语句</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#多个语句构成代码组"><span class="nav-number">1.3.0.0.3.</span> <span class="nav-text">多个语句构成代码组</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#命令行参数"><span class="nav-number">1.3.0.0.4.</span> <span class="nav-text">命令行参数</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#import与from…import"><span class="nav-number">1.3.0.0.5.</span> <span class="nav-text">import与from…import</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#解释器"><span class="nav-number">1.3.0.0.6.</span> <span class="nav-text">解释器</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#日期和时间"><span class="nav-number">1.3.0.0.7.</span> <span class="nav-text">日期和时间</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#函数"><span class="nav-number">1.3.0.0.8.</span> <span class="nav-text">函数</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#模块"><span class="nav-number">1.3.0.0.9.</span> <span class="nav-text">模块</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#文件I-O"><span class="nav-number">1.3.0.0.10.</span> <span class="nav-text">文件I&#x2F;O</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Python高级篇"><span class="nav-number">1.4.</span> <span class="nav-text">Python高级篇</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="heweiliang"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">heweiliang</p>
  <div class="site-description" itemprop="description">heweiliang blog</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">96</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:yourname@gmail.com" title="E-Mail → mailto:yourname@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://plus.google.com/yourname" title="Google → https:&#x2F;&#x2F;plus.google.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-google"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://stackoverflow.com/yourname" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-stack-overflow"></i></a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title2</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title3</a>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">heweiliang</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">376k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">5:42</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/three-waves.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>


  




  
<script src="/js/local-search.js"></script>













  

  

<script>
NexT.utils.loadComments(document.querySelector('#lv-container'), () => {
  window.livereOptions = {
    refer: location.pathname.replace(CONFIG.root, '').replace('index.html', '')
  };
  (function(d, s) {
    var j, e = d.getElementsByTagName(s)[0];
    if (typeof LivereTower === 'function') { return; }
    j = d.createElement(s);
    j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
    j.async = true;
    e.parentNode.insertBefore(j, e);
  })(document, 'script');
});
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/Epsilon2.1.model.json"},"display":{"position":"left","width":300,"height":600},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
